#include "StdAfx.h"
#include "component_connector.h"
#include "tools.h"

component_connector::component_connector(void)
{
	previous_position[0] = 0.0f;
	previous_position[1] = 0.0f;
	previous_position[2] = 0.0f;
	previous_valid = false;
}


component_connector::~component_connector(void)
{
}

void component_connector::clear()
{
	::path_component::clear();
	previous_position[0] = 0.0f;
	previous_position[1] = 0.0f;
	previous_position[2] = 0.0f;
	previous_valid = false;
}

void component_connector::draw(float* start, float* end, float start_dist, float end_dist, float* delta)
{
	//position
	float towards[3] = {end[0]-start[0], end[1]-start[1], end[2]-start[2]};
	float path_length = end_dist - start_dist;
	//phrase
	float start_phrase = phrase + start_dist / cycle;
	float cur_dist_along_path = cycle * (1.0f - float_mod(start_phrase, 1.0f));
	for(;cur_dist_along_path < path_length; cur_dist_along_path += cycle)
	{
		float position[3] = {start[0] + cur_dist_along_path * towards[0]/path_length,
			start[1] + cur_dist_along_path * towards[1]/path_length,
			start[2] + cur_dist_along_path * towards[2]/path_length};
		
		if(previous_valid)
		{
			draw_element(position, previous_position, delta, previous_delta);
		}

		previous_position[0] = position[0];
		previous_position[1] = position[1];
		previous_position[2] = position[2];
		previous_delta[0] = delta[0];
		previous_delta[1] = delta[1];
		previous_delta[2] = delta[2];
		previous_valid = true;	
	}
}

void component_connector::draw_corner(float *previous_point, float *cur_point, 
								float* previous_delta, float *cur_delta, 
								float* center_point, float corner_radius)
{
	/*
	float delta[3] = { (cur_delta[0] + previous_delta[0])*0.5f,
		0.0f,
		(cur_delta[2] + previous_delta[2])*0.5f};
	
	if(previous_valid)
	{
		draw_element(center_point,previous_position,delta,previous_delta);
	}

	previous_position[0] = center_point[0];
	previous_position[1] = center_point[1];
	previous_position[2] = center_point[2];

	this->previous_delta[0] = delta[0];
	this->previous_delta[1] = delta[1];
	this->previous_delta[2] = delta[2];
	
	previous_valid = true;
	*/
	
}